﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Demo.TspDemo.ServiceSSVG;
using Net_Trading;
using System.Net;
using System.IO;
namespace Demo.TspDemo
{
    public partial class fen_chauffeur : Form
    {
        public fen_chauffeur()
        {
            InitializeComponent();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void fen_chauffeur_Load(object sender, EventArgs e)
        {
            Singleton s = Singleton.Instance;
            panel_ajout.Visible = false;
            panel_modif.Visible = false;
            if (!s.Modif)
            {
                panel_ajout.Visible = true;
            }
            else
            {
                panel_modif.Visible = true;
                using (Service1 serv = new Service1())
                {
                    var emp = serv.ConsulterChauffeur(s.Id);
                    textEdit8.Text = emp.Nom;
                    textEdit7.Text = emp.Prenom;
                    textEdit6.Text = emp.Adresse;
                    textEdit5.Text = emp.Email;
                    textEdit4.Text = emp.Tel;
                    textEdit3.Text = emp.Login;
                    textEdit2.Text = emp.Password;
                    textEdit1.Text = emp.Image;
                }
            }
            
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            //modifier chauffeur
            Singleton s = Singleton.Instance;
            using (Service1 serv = new Service1())
            {
                if (textEdit8.Text == "" || textEdit7.Text == "" || textEdit3.Text == "" || textEdit2.Text == "")
                    MessageBox.Show("Veillez remplir les champs obligatoires!");
                else
                    if (serv.ModifierChauffeur(textEdit8.Text, textEdit7.Text,textEdit6.Text,textEdit4.Text,textEdit3.Text,textEdit2.Text,textEdit1.Text,textEdit5.Text,s.Id))
                    {
                        MessageBox.Show("Modification Effectuée avec Succès !");
                        this.Close();
                    }
                    else
                        MessageBox.Show("Modification Impossible !");
            }
        }

        private void simpleButton5_Click(object sender, EventArgs e)
        {

            using (OpenFileDialog open = new OpenFileDialog())
            {
                // image filters
                open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
                if (open.ShowDialog() == DialogResult.OK)
                    textEdit1.Text = open.FileName;
            }

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (textEdit16.Text == "" || textEdit15.Text == "" || textEdit11.Text == "" || textEdit10.Text == "")
            {
                MessageBox.Show("Veillez remplir les champs obligatoires!");
            }
            else
            {
                Service1 serv = new Service1();
                if (serv.AjouterChauffeur(textEdit16.Text, textEdit15.Text, textEdit14.Text, textEdit12.Text, textEdit13.Text, textEdit9.Text, textEdit11.Text, textEdit10.Text))
                {
                    MessageBox.Show("Enregistrement Effectué avec Succès !");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Enregistrement Impossible !");

                }
            }
        }
    }
}
